package com.dkt.blogboot.mapper;
import com.dkt.blogboot.entity.Article;
import com.dkt.blogboot.resp.ArticleQueryResp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
*@author 窦康泰
*@date 2021/07/04
*/
@Repository
public interface ArticleMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Article record);

    int insertSelective(Article record);

    Article selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Article record);

    int updateByPrimaryKey(Article record);

    List<ArticleQueryResp> select(@Param("offset") Integer offset, @Param("size") Integer size,@Param("uid") Integer uid);

    List<ArticleQueryResp> selectHistory(@Param("offset") Integer offset, @Param("size") Integer size,@Param("uid") Integer uid);

    Integer count(@Param("uid") Integer uid);

    ArticleQueryResp selectOneById(@Param("id")Integer id);

    List<Article> selectAllByCategoryId(Integer id);

    List<Article> selectAllByTagId(Integer id);

    List<Article> selectAll();

    List<ArticleQueryResp> selectByTitle(@Param("offset") Integer offset, @Param("size") Integer size, @Param("title") String title,@Param("uid") Integer uid);

    Integer countByTitleLike(@Param("likeTitle")String likeTitle);

    List<ArticleQueryResp> selectArticleAll(@Param("offset") Integer offset, @Param("size") Integer size);

    Integer Allcount();

    @Select("select * from article where status = 0 and date < #{twoMonthAgo}")
    List<Article> selectArticlesToMove(LocalDateTime twoMonthAgo);

    @Update("update article set status=0 where date < #{twoMonthAgo}")
    void updateStatus(LocalDateTime twoMonthAgo);

    @Update("update article set coldFlag=1 where id=#{id}")
    void updateColdFlag(Integer id);

    @Select("select * from article where coldFlag=1")
    List<Article> selectArticlesByColdFlag();

    @Delete("delete from article where id=#{id}")
    void deleteTicket(Integer id);

    List<ArticleQueryResp> select2(@Param("offset") Integer offset, @Param("size") Integer size,@Param("uid") Integer uid);
}